annolid.annotation package¶
Submodules¶
annolid.annotation.coco2yolo module¶
-
annolid.annotation.coco2yolo.
create_dataset
(json_file='annotation.json', results_dir='yolo_dataset', dataset_type='train', class_id=None, is_segmentation=None)[source]¶ Convert COCO format dataset to YOLOV format
- Parameters
json_file (str, optional) – file path for annotation.json. Defaults to ‘annotation.json’.
results_dir (str, optional) – result directory. Defaults to ‘yolov5_dataset’.
dataset_type (str, optional) – train or val or test. Defaults to ‘train’.
class_id (int, optional) – class id. Defaults to None.
is_segmentation (bool, optional) – segmentation or detection. Defaults to None.
For example the YOLOV8 format train
- images
1.jpg 2.jpg
- labels
1.txt 2.txt
Inside the 1.txt, the first value is class id, cx, cy, width, height, rest of them are x, y pairs 0 0.6481018062499999 0.2623046875 0.6664123531249999 0.2623046875 0.6526794437500001 0.1952907984375
0.62596435625 0.18576388906250002 0.6037536625000001 0.189420571875 0.6072265625 0.21825086875 0.6204650875 0.24717881875 0.6481018062499999 0.2623046875
How to use this with command line? python annolid/main.py –coco2yolo /test_yolov_coco_dataset/train/annotations.json –dataset_type train –to test_yolov/
How to convert COCO format dataset to YOLOV8 detection bbox format? python annolid/main.py –coco2yolo ~/Downloads/Testframes_coco_dataset/train/annotations.json –dataset_type train –to ~/Downloads/test_mouse/ –seg_or_detect detect | seg
- Returns
a list of labeled class names
- Return type
list
-
annolid.annotation.coco2yolo.
xywh2cxcywh
(box, img_size)[source]¶ convert COCO bounding box format to YOLO format. The YOLO format bounding box values were normalized with width and height values
- Parameters
box (list) – COCO bounding box format (x_top_left, y_top_left, width, height)
img_size (tuple) – (img_width, img_height)
- Returns
normalized YOLO format bounding box (x_center,y_center, width, height)
- Return type
tuple